<?php
/**
 * 简历管理
 */

class EAdmin_Page_ResumeScoreSet extends EAdmin_Page_Abstract
{
	public function validate(ME_Request $input, ME_Response $output)
	{

		return true;
	}
	private function loadDb()
	{
		$this->resumeDb = Db_Resume::instance();
	}

	public function doDefault(ME_Request $input, ME_Response $output)
	{
		$uid = $input->get("uid");
		$view = $input->get('view');
		$uid = !empty($uid) ? $uid : 0;
		if($uid == 0){
			return false;
		}

		$euserInfo = Libs_EUser::getLoginStatus($input,$output);
		$output->eid = 
			$input->eid =
			$eid = $euserInfo[0];

		$output->uid = $input->uid = $uid;
		$output->eid = $input->eid = $eid;

		$output->myResumeConfig = 
			$myResumeConfig = ME_Config::get("MyResume");

		$output->scoreField = $scoreField = Libs_EUser::getEScoreField($eid);

		if($view){
			$user_score = Libs_EUser::getResumeScore(array('uid'=>$uid,'eid'=>$eid));
			$output->view_detail = 
			$view_detail = unserialize($user_score['detail']);
			$output->view_total =
			$view_total = $user_score['total'];
			$output->view_commit =
			$view_commit = $user_score['commit'];
		}

		/***************************************************************/

		$this->loadDb();
		$output->pageType = 'preView';

		//区域隐藏信息
		$areaHideArr         = EAdmin_Plugin_MyResume::getAreaHideValueArr($input,$output);
		$output->areaHideArr = $areaHideArr;

		$output->baseInfo = EAdmin_Plugin_MyResume::getBaseInfo($input,$output);

		if($output->adminView || !isset($areaHideArr['edu']) || $areaHideArr['edu']) $output->eduList = EAdmin_Plugin_MyResume::getEduInfo($input,$output);

		if($output->adminView || !isset($areaHideArr['other']) || $areaHideArr['other']) $output->otherList = EAdmin_Plugin_MyResume::getOtherInfo($input,$output);

		if($output->adminView || !isset($areaHideArr['schoolaward']) || $areaHideArr['schoolaward']) $output->schoolAwardList = EAdmin_Plugin_MyResume::getSchoolAwardInfo($input,$output);

		if($output->adminView || !isset($areaHideArr['position']) || $areaHideArr['position']) $output->positionList    = EAdmin_Plugin_MyResume::getPositionInfo($input,$output);

		$output->languageList = EAdmin_Plugin_MyResume::getLanguageInfo($input, $output);
		$output->projectList = EAdmin_Plugin_MyResume::getProjectInfo($input, $output);
		$output->jobList = EAdmin_Plugin_MyResume::getJobInfo($input, $output);
		$output->jobhistoryList = EAdmin_Plugin_MyResume::getJobHistoryInfo($input, $output);
		$output->trainList = EAdmin_Plugin_MyResume::getTrainInfo($input, $output);
		$output->certList = EAdmin_Plugin_MyResume::getCertInfo($input, $output);
		$output->itList = EAdmin_Plugin_MyResume::getITInfo($input, $output);

		$output->setTemplate('ResumeScoreSet');

	}
	

	public function doScore(ME_Request $input, ME_Response $output)
	{
		$uid = $input->post("uid");	
		$eid = $input->post("eid");	
		$commit = $input->post("commit");

		if($uid == 0 || $eid == 0){
			echo '<script>alert("参数出错，请重新登录以后再进行评分！");</script>';
			exit;
		}

		$scoreField = Libs_EUser::getEScoreField($eid);
		$fieldArr = array();
		if($scoreField){
			foreach($scoreField as $field){
				$fieldArr[$field['id']] = $field['weight'];	
			}	
		}

		$params = $input->getByMethod('','post');
		unset($params['uid']);
		unset($params['eid']);
		unset($params['commit']);

		$score_arr = array();
		$total_score = 0;
		if($params){
			foreach($params as $key=>$val){
				$field_id = trim(strstr($key,"_"),"_");
				$score_arr[$field_id] = $val;
				$total_score = $val * $fieldArr[$field_id] / 100;
			}	
		}
		
		$score_detail = serialize($score_arr);
		$re = Libs_EUser::storeResumeScore(array("eid"=>$eid, "uid"=>$uid, "detail"=>$score_detail, "total"=>$total_score,"commit"=>$commit));

		if($re){
			echo "<script>alert('评分成功');window.location='index.php?c=ResumeManage';</script>";
			exit;
		}

		die("<script>alert('评分失败');history.go(-1);");
	}

}
